import { createRouter, createWebHashHistory } from 'vue-router';
import { useTitleStore } from '@/store';
import Home from '@/view/Home/index.vue';
import About from '@/view/About/index.vue';
import Game from '@/view/Game/index.vue'

const routes = [
  // {
  //   path: '/',
  //   name: 'Home',
  //   component: Home,
  //   meta: { title: '首页' },
  // },
  {
    path: '/about',
    name: 'About',
    component: About,
    meta: { title: '关于我们' },
  },
  {
    path: '/',
    name: 'Game',
    component: Game,
    meta: { title: 'Battle City 2025' },
  }
];

// 使用 createWebHashHistory 兼容 Electron 文件协议
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// router变化 同步修改title
router.afterEach((to) => {
  // document.title = to.meta.title || 'Sala'
  const store = useTitleStore()
  store.title = to.meta.title || 'Sala'
})

export default router;
